//
//  RCMerchantPictureViewController.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-30.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantPictureViewController.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "NSString+NSString_Ex_.h"
#import "GloableEngineService.h"
#import "RCMerchantDetailVC.h"
#import "AppDelegate.h"
#import "NSArray+EX.h"
#import <QuartzCore/QuartzCore.h>
#import "RCMerchantAlbumDetailViewController.h"
#import "BTCityAndSceneScrollViewController.h"
#import "RCMerchantUploadPhotoViewController.h"
#import "RCFansListVC.h"

#define kHeaderViewFrame      CGRectMake(0,0,320,44)

#define kHeaderLineImageFile           @"image_line_type3.png"
#define kRightButtonImageFile          @"image_merchant_pictureAlbum.png"
#define kManageButtonImageFile         @"image_shopManager_managerPhoto.png"

@interface RCMerchantPictureViewController ()<LVPhotoPreviewViewControllerDelegate>

@property(nonatomic,retain) NSString *shopID;
@property(nonatomic,retain) NSString *shopName;
@property(nonatomic,retain) UIView *headerView;
@property(nonatomic,retain) UIButton *dishButton;
@property(nonatomic,retain) UILabel *dishLabel;
@property(nonatomic,retain) UIButton *environmentButton;
@property(nonatomic,retain) UILabel *environmentLabel;
@property(nonatomic,retain) UIButton *priceButton;
@property(nonatomic,retain) UILabel *priceLabel;
@property(nonatomic,retain) UIButton *othersButton;
@property(nonatomic,retain) UILabel *othersLabel;
@property(nonatomic,retain) UIButton *allButton;
@property(nonatomic,retain) UILabel *allLabel;
@property(nonatomic,retain) UIView *subView;
@property(nonatomic,assign) MerchantPictureType pageType;
@property(nonatomic,retain) MBProgressHUDEx *progressHub;
@property(nonatomic,retain) RCMerchantPictureSubView *dishSubView;
@property(nonatomic,retain) RCMerchantPictureSubView *priceSubView;
@property(nonatomic,retain) RCMerchantPictureSubView *othersSubView;
@property(nonatomic,retain) RCMerchantPictureSubView *environmentSubView;
@property(nonatomic,retain) RCMerchantPictureSubView *allSubView;

@property(nonatomic,retain) NSMutableArray *tagButtonArray;
@property(nonatomic,retain) NSMutableArray *tagLabelArray;
@property(nonatomic,assign) int64_t requestID;
@property(nonatomic,retain) RCMerchantPicturesDataModel *dataModel;
@property(nonatomic,retain) UIButton *rightButton;
@property(nonatomic,retain) UIButton *manageButton;

@end

@implementation RCMerchantPictureViewController

@synthesize shopID = _shopID;
@synthesize shopName = _shopName;
@synthesize headerView = _headerView;
@synthesize dishButton = _dishButton;
@synthesize dishLabel = _dishLabel;
@synthesize priceButton = _priceButton;
@synthesize priceLabel = _priceLabel;
@synthesize othersButton = _othersButton;
@synthesize othersLabel = _othersLabel;
@synthesize environmentButton = _environmentButton;
@synthesize environmentLabel = _environmentLabel;
@synthesize allButton = _allButton;
@synthesize allLabel = _allLabel;
@synthesize subView = _subView;
@synthesize pageType = _pageType;
@synthesize progressHub = _progressHub;
@synthesize dishSubView = _dishSubView;
@synthesize priceSubView = _priceSubView;
@synthesize othersSubView = _othersSubView;
@synthesize environmentSubView = _environmentSubView;
@synthesize allSubView = _allSubView;

@synthesize tagButtonArray = _tagButtonArray;
@synthesize tagLabelArray = _tagLabelArray;
@synthesize requestID = _requestID;
@synthesize dataModel = _dataModel;
@synthesize rightButton = _rightButton;
@synthesize manageButton = _manageButton;
@synthesize isFromServer = _isFromServer;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(id)initWithShopID:(NSString *)shopID andShopName:(NSString *)shopName{
    self = [super init];
    if (self) {
        self.shopID = shopID;
        self.shopName = shopName;
    }
    return self;
}

-(void)dealloc{
    self.shopID = nil;
    self.shopName = nil;
    self.dishButton = nil;
    self.dishLabel = nil;
    self.priceButton = nil;
    self.priceLabel = nil;
    self.othersButton = nil;
    self.othersLabel = nil;
    self.environmentButton = nil;
    self.environmentLabel = nil;
    self.allButton = nil;
    self.allLabel = nil;
    self.headerView = nil;
    self.progressHub.delegate = nil;
    self.progressHub = nil;
    self.dishSubView = nil;
    self.priceSubView = nil;
    self.othersSubView = nil;
    self.environmentSubView = nil;
    self.allSubView = nil;
    self.subView = nil;
    self.tagButtonArray = nil;
    self.tagLabelArray = nil;
    self.dataModel = nil;
    self.rightButton = nil;
    self.manageButton = nil;
    
    [super dealloc];
}

-(void)loadView{
    [super loadView];
    
    _rightButton = [[UIButton alloc]initWithFrame:CGRectMake(44, 0, 44, 44)];
    [_rightButton setImage:[UIImage imageNamed:kRightButtonImageFile]
                  forState:UIControlStateNormal];
    [_rightButton setImage:[UIImage imageNamed:kRightButtonImageFile]
                  forState:UIControlStateHighlighted];
    [_rightButton addTarget:self action:@selector(rightButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _manageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
    [_manageButton setImage:[UIImage imageNamed:kManageButtonImageFile]
                  forState:UIControlStateNormal];
    [_manageButton setImage:[UIImage imageNamed:kManageButtonImageFile]
                  forState:UIControlStateHighlighted];
    [_manageButton addTarget:self action:@selector(manageButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [self createRightBarButtonItemWithButton:_manageButton withSecondButton:_rightButton];
    
    if (self.isFromServer) {
        self.titleLabelText = @"相册";
        self.navigationItem.titleView = [self createTitleView];
    }else{
        self.navigationItem.titleView = [self createTwolineTitleView];
        _manageButton.hidden = YES;
    }
    
    
}

-(UIView *)createTwolineTitleView{
    UIView *titleView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 44)]autorelease];
    UILabel *upperLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, 150, 15)];
    upperLabel.backgroundColor = [UIColor clearColor];
    upperLabel.textColor = [UIColor whiteColor];
    upperLabel.textAlignment = UITextAlignmentCenter;
    upperLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    upperLabel.shadowColor = [UIColor colorWithHex:0xff2c2c2];
    upperLabel.shadowOffset = CGSizeMake(0, 0.5);
    upperLabel.text = @"相册";
    [titleView addSubview:upperLabel];
    [upperLabel release];
    
    UILabel *downLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 24, 150, 15)];
    downLabel.backgroundColor = [UIColor clearColor];
    downLabel.textColor = [UIColor whiteColor];
    downLabel.textAlignment = UITextAlignmentCenter;
    downLabel.font = [UIFont fontWithName:kFontNameHeiti size:15];
    downLabel.shadowColor = [UIColor colorWithHex:0xff2c2c2];
    downLabel.shadowOffset = CGSizeMake(0, 0.5);
    downLabel.text = self.shopName;
    [titleView addSubview:downLabel];
    [downLabel release];
    return titleView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _tagButtonArray = [[NSMutableArray alloc]initWithCapacity:5];
    _tagLabelArray = [[NSMutableArray alloc]initWithCapacity:5];
    
    _headerView = [[UIView alloc]initWithFrame:kHeaderViewFrame];
    _headerView.backgroundColor = [UIColor colorWithHex:0xffdcdcdc];
    
    _dishButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 8, 64, 28)];
    [_dishButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_dishButton setBackgroundColor:[UIColor clearColor]];
    _dishButton.tag = MerchantPictureTypeDish+100;
    _dishButton.layer.masksToBounds = YES;
    _dishButton.layer.cornerRadius = 3.0f;
    [_dishButton addTarget:self action:@selector(switchButtonCategory:) forControlEvents:UIControlEventTouchUpInside];
    
    _dishLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 7, 64, 14)];
    _dishLabel.backgroundColor = [UIColor clearColor];
    _dishLabel.textColor = [UIColor colorWithHex:0xff505050];
    _dishLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _dishLabel.textAlignment = UITextAlignmentCenter;
    _dishLabel.text = @"菜";
    [_dishButton addSubview:_dishLabel];
    [_headerView addSubview:_dishButton];
    
    [_tagButtonArray addObject:_dishButton];
    [_tagLabelArray addObject:_dishLabel];
    
    _environmentButton = [[UIButton alloc]initWithFrame:CGRectMake(64, 8, 64, 28)];
    [_environmentButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_environmentButton setBackgroundColor:[UIColor clearColor]];
    [_environmentButton addTarget:self action:@selector(switchButtonCategory:) forControlEvents:UIControlEventTouchUpInside];
    _environmentButton.tag = MerchantPictureTypeEnvironment +100;
    _environmentButton.layer.masksToBounds = YES;
    _environmentButton.layer.cornerRadius = 3.0f;
    
    _environmentLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 7, 64, 14)];
    _environmentLabel.backgroundColor = [UIColor clearColor];
    _environmentLabel.textColor = [UIColor colorWithHex:0xff505050];
    _environmentLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _environmentLabel.textAlignment = UITextAlignmentCenter;
    _environmentLabel.text = @"环境";
    [_environmentButton addSubview:_environmentLabel];
    [_headerView addSubview:_environmentButton];
    
    [_tagButtonArray addObject:_environmentButton];
    [_tagLabelArray addObject:_environmentLabel];
    
    _priceButton = [[UIButton alloc]initWithFrame:CGRectMake(128, 8, 64, 28)];
    [_priceButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_priceButton setBackgroundColor:[UIColor clearColor]];
    [_priceButton addTarget:self action:@selector(switchButtonCategory:) forControlEvents:UIControlEventTouchUpInside];
    _priceButton.tag = MerchantPictureTypePrice+100;
    _priceButton.layer.masksToBounds = YES;
    _priceButton.layer.cornerRadius = 3.0f;
    
    _priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 7, 64, 14)];
    _priceLabel.backgroundColor = [UIColor clearColor];
    _priceLabel.textColor = [UIColor colorWithHex:0xff505050];
    _priceLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _priceLabel.textAlignment = UITextAlignmentCenter;
    _priceLabel.text = @"价目表";
    
    [_priceButton addSubview:_priceLabel];
    [_headerView addSubview:_priceButton];
    
    [_tagButtonArray addObject:_priceButton];
    [_tagLabelArray addObject:_priceLabel];
    
    _othersButton = [[UIButton alloc]initWithFrame:CGRectMake(192, 8, 64, 28)];
    [_othersButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_othersButton setBackgroundColor:[UIColor clearColor]];
    [_othersButton addTarget:self action:@selector(switchButtonCategory:) forControlEvents:UIControlEventTouchUpInside];
    _othersButton.tag = MerchantPictureTypeOthers +100;
    _othersButton.layer.masksToBounds = YES;
    _othersButton.layer.cornerRadius = 3.0f;
    
    _othersLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 7, 64, 14)];
    _othersLabel.backgroundColor = [UIColor clearColor];
    _othersLabel.textColor = [UIColor colorWithHex:0xff505050];
    _othersLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _othersLabel.textAlignment = UITextAlignmentCenter;
    _othersLabel.text = @"其他";
    [_othersButton addSubview:_othersLabel];
    [_headerView addSubview:_othersButton];
    
    [_tagButtonArray addObject:_othersButton];
    [_tagLabelArray addObject:_othersLabel];
    
    
    _allButton = [[UIButton alloc]initWithFrame:CGRectMake(256, 8, 64, 28)];
    [_allButton setBackgroundImage:nil forState:UIControlStateNormal];
    [_allButton setBackgroundColor:[UIColor clearColor]];
    [_allButton addTarget:self action:@selector(switchButtonCategory:) forControlEvents:UIControlEventTouchUpInside];
    _allButton.tag = MerchantPictureTypeAll +100;
    _allButton.layer.masksToBounds = YES;
    _allButton.layer.cornerRadius = 3.0f;
    
    _allLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 7, 64, 14)];
    _allLabel.backgroundColor = [UIColor clearColor];
    _allLabel.textColor = [UIColor colorWithHex:0xff505050];
    _allLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:14];
    _allLabel.textAlignment = UITextAlignmentCenter;
    _allLabel.text = @"全部";
    [_allButton addSubview:_allLabel];
    [_headerView addSubview:_allButton];
    
    [_tagButtonArray addObject:_allButton];
    [_tagLabelArray addObject:_allLabel];
    
    UIImageView *headlineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 43, 320, 1)];
    headlineImageView.backgroundColor = [UIColor clearColor];
    [headlineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kHeaderLineImageFile ofType:nil]]];
    [_headerView addSubview:headlineImageView];
    [headlineImageView release];
    
    [self.viewContainer addSubview:_headerView];
    [self.viewContainer setMultipleTouchEnabled:NO];
    
    if (!_subView) {
        _subView = [[UIView alloc]initWithFrame:CGRectMake(0, 44, 320, UIScreenHeight-20-44-44)];
        _subView.backgroundColor = [UIColor clearColor];
    }
    [self.viewContainer addSubview:_subView];
    
    if (!_progressHub)
    {
        _progressHub = [[MBProgressHUDEx alloc] initWithView:self.view TopHeight:self.subView.frame.origin.y withBottomHeight:0 withLeftWidth:0 withRightWidth:0 withExclusiveObjects:nil];
        [self.view addSubview:_progressHub];
    }
    [_progressHub setFrameWithView:self.view
                         TopHeight:self.subView.frame.origin.y
                  withBottomHeight:0
                     withLeftWidth:0
                    withRightWidth:0];
    [self.view bringSubviewToFront:_progressHub];
    _progressHub.delegate = self;
    _progressHub.labelText= @"加载中...";
    [_progressHub show:YES];
    
    // current select button is scene
    [self switchButtonCategory:_allButton];
    
    
	// Do any additional setup after loading the view.
}


#pragma -mark ToplistTypeViewDelegate

-(void)refreshHeaderButtonWithCategoryID{
    
    
    for (UIButton *button in _tagButtonArray) {
        button.hidden = YES;
    }

    NSArray *typeItemArray = self.dataModel.albumArray;
    NSInteger buttonIndex = 0;
    for (int i=0; i < [typeItemArray count]; i++) {
        rcMerchantPictureSubAlbum *typeItem = [typeItemArray safeObjectAtIndex:i];
        if (nil == typeItem || [typeItem.typeName isEqualToString:@"全部"]) {
            continue;
        }
        
        UIButton *button = [_tagButtonArray safeObjectAtIndex:buttonIndex];
        if (button) {
            button.hidden = NO;
        }
        
        UILabel *label = [_tagLabelArray safeObjectAtIndex:buttonIndex];
        if (label) {
            label.text = typeItem.typeName;
        }
        buttonIndex++;
    }
    
    CGFloat width =([typeItemArray count]-1)*64;
    _allButton.frame = CGRectMake(width, 8, 64, 28);
    _allButton.hidden = NO;
    
}


-(void)createDishSubView{
    if (!_dishSubView) {
        
        NSString *typeID = nil;
        NSInteger index = 0;
        for (int i = 0; i < [self.dataModel.albumArray count];i++ ) {
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:i];
            if (nil == typeItem || [typeItem.typeName isEqualToString:@"全部"]) {
                continue;
            }
            typeID = typeItem.typeID;
            index++;
            if (index >=1) {
                break;
            }
        }
        
        
        _dishSubView = [[RCMerchantPictureSubView alloc]initWithFrame:self.subView.bounds andDelegate:self andType:typeID andMerchantID:self.shopID andPageType:MerchantPictureTypeDish];
        _dishSubView.delegate = self;
        _dishSubView.backgroundColor = [UIColor clearColor];
        _dishSubView.baseTableView.backgroundColor = [UIColor clearColor];
        _dishSubView.hidden = YES;
        [self.subView addSubview:_dishSubView];
        _dishSubView.baseTableView.frame = self.subView.bounds;
    }
}
-(void)createPriceSubView{
    if (!_priceSubView) {
        
        NSString *typeID = nil;
        NSInteger index = 0;
        for (int i = 0; i < [self.dataModel.albumArray count];i++ ) {
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:i];
            if (nil == typeItem || [typeItem.typeName isEqualToString:@"全部"]) {
                continue;
            }
            typeID = typeItem.typeID;
            index++;
            if (index >=3) {
                break;
            }
        }
        
        _priceSubView = [[RCMerchantPictureSubView alloc]initWithFrame:self.subView.bounds andDelegate:self andType:typeID andMerchantID:self.shopID andPageType:MerchantPictureTypePrice];
        _priceSubView.delegate = self;
        _priceSubView.backgroundColor = [UIColor clearColor];
        _priceSubView.baseTableView.backgroundColor = [UIColor clearColor];
        _priceSubView.hidden = YES;
        [self.subView addSubview:_priceSubView];
        _priceSubView.baseTableView.frame = self.subView.bounds;
    }
}
-(void)createOthersSubView{
    if (!_othersSubView) {
        
        NSString *typeID = nil;
        NSInteger index = 0;
        for (int i = 0; i < [self.dataModel.albumArray count];i++ ) {
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:i];
            if (nil == typeItem || [typeItem.typeName isEqualToString:@"全部"]) {
                continue;
            }
            typeID = typeItem.typeID;
            index++;
            if (index >=4) {
                break;
            }
        }
        
        _othersSubView = [[RCMerchantPictureSubView alloc]initWithFrame:self.subView.bounds andDelegate:self andType:typeID andMerchantID:self.shopID andPageType:MerchantPictureTypeOthers];
        _othersSubView.delegate = self;
        _othersSubView.backgroundColor = [UIColor clearColor];
        _othersSubView.baseTableView.backgroundColor = [UIColor clearColor];
        _othersSubView.hidden = YES;
        [self.subView addSubview:_othersSubView];
        _othersSubView.baseTableView.frame = self.subView.bounds;
    }
}
-(void)createEnvironmentSubView{
    if (!_environmentSubView) {
        
        NSString *typeID = nil;
        NSInteger index = 0;
        for (int i = 0; i < [self.dataModel.albumArray count];i++ ) {
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:i];
            if (nil == typeItem || [typeItem.typeName isEqualToString:@"全部"]) {
                continue;
            }
            typeID = typeItem.typeID;
            index++;
            if (index >=2) {
                break;
            }
        }
        
        
        _environmentSubView = [[RCMerchantPictureSubView alloc]initWithFrame:self.subView.bounds andDelegate:self andType:typeID andMerchantID:self.shopID andPageType:MerchantPictureTypeEnvironment];
        _environmentSubView.delegate = self;
        _environmentSubView.backgroundColor = [UIColor clearColor];
        _environmentSubView.baseTableView.backgroundColor = [UIColor clearColor];
        _environmentSubView.hidden = YES;
        [self.subView addSubview:_environmentSubView];
        _environmentSubView.baseTableView.frame = self.subView.bounds;
    }
}

-(void)createAllSubView{
    if (!_allSubView) {
        
        NSString *typeID = nil;
        for (int i = 0; i < [self.dataModel.albumArray count]; i++) {
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:i];
            if (nil == typeItem) {
                continue;
            }
            if ([typeItem.typeName isEqualToString:@"全部"]) {
                typeID = typeItem.typeID;
                break;
            }
        }
        if ([NSString stringIsNullOrEmpty:typeID]) {
//            NSInteger count = [self.dataModel.albumArray count]-1;
            rcMerchantPictureSubAlbum *typeItem = [self.dataModel.albumArray safeObjectAtIndex:0];
            typeID = typeItem.typeID;
        }
        
        
        
        _allSubView = [[RCMerchantPictureSubView alloc]initWithFrame:self.subView.bounds andDelegate:self andType:typeID andMerchantID:self.shopID andPageType:MerchantPictureTypeAll];
        _allSubView.delegate = self;
        _allSubView.backgroundColor = [UIColor clearColor];
        _allSubView.baseTableView.backgroundColor = [UIColor clearColor];
        _allSubView.hidden = YES;
        [self.subView addSubview:_allSubView];
        _allSubView.baseTableView.frame = self.subView.bounds;
    }
}


-(void)switchButtonCategory:(id)sender{
    UIButton *button = (UIButton *)sender;
    NSInteger tagNum = button.tag;
    MerchantPictureType type = tagNum-100;
    
    
    self.pageType = type;
    switch (type) {
        case MerchantPictureTypeDish:{
            
            [_dishButton setBackgroundColor:[UIColor colorWithHex:0xffbdbbbb]];
            [_priceButton setBackgroundColor:[UIColor clearColor]];
            [_othersButton setBackgroundColor:[UIColor clearColor]];
            [_environmentButton setBackgroundColor:[UIColor clearColor]];
            [_allButton setBackgroundColor:[UIColor clearColor]];
            
            [self createDishSubView];
            _dishSubView.hidden = NO;
            if (_priceSubView) {
                _priceSubView.hidden = YES;
            }
            if (_othersSubView) {
                _othersSubView.hidden = YES;
            }
            if (_environmentSubView) {
                _environmentSubView.hidden = YES;
            }
            if (_allSubView) {
                _allSubView.hidden = YES;
            }
            
            [_dishSubView reloadData];
            [self.subView bringSubviewToFront:_dishSubView];
            
            break;
        }
        case MerchantPictureTypePrice:{
            
            [_dishButton setBackgroundColor:[UIColor clearColor]];
            [_priceButton setBackgroundColor:[UIColor colorWithHex:0xffbdbbbb]];
            [_othersButton setBackgroundColor:[UIColor clearColor]];
            [_environmentButton setBackgroundColor:[UIColor clearColor]];
            [_allButton setBackgroundColor:[UIColor clearColor]];
            
            [self createPriceSubView];
            _priceSubView.hidden = NO;
            if (_dishSubView) {
                _dishSubView.hidden = YES;
            }
            if (_othersSubView) {
                _othersSubView.hidden = YES;
            }
            if (_environmentSubView) {
                _environmentSubView.hidden = YES;
            }
            if (_allSubView) {
                _allSubView.hidden = YES;
            }
            
            [_priceSubView reloadData];
            [self.subView bringSubviewToFront:_priceSubView];
            break;
        }
        case MerchantPictureTypeOthers:{
            
            [_dishButton setBackgroundColor:[UIColor clearColor]];
            [_priceButton setBackgroundColor:[UIColor clearColor]];
            [_othersButton setBackgroundColor:[UIColor colorWithHex:0xffbdbbbb]];
            [_environmentButton setBackgroundColor:[UIColor clearColor]];
            [_allButton setBackgroundColor:[UIColor clearColor]];
            
            [self createOthersSubView];
            _othersSubView.hidden = NO;
            if (_dishSubView) {
                _dishSubView.hidden = YES;
            }
            if (_priceSubView) {
                _priceSubView.hidden = YES;
            }
            if (_environmentSubView) {
                _environmentSubView.hidden = YES;
            }
            if (_allSubView) {
                _allSubView.hidden = YES;
            }
            
            [_othersSubView reloadData];
            [self.subView bringSubviewToFront:_othersSubView];
            break;
        }
        case MerchantPictureTypeEnvironment:{
            
            [_dishButton setBackgroundColor:[UIColor clearColor]];
            [_priceButton setBackgroundColor:[UIColor clearColor]];
            [_othersButton setBackgroundColor:[UIColor clearColor]];
            [_environmentButton setBackgroundColor:[UIColor colorWithHex:0xffbdbbbb]];
            [_allButton setBackgroundColor:[UIColor clearColor]];
            
            [self createEnvironmentSubView];
            _environmentSubView.hidden = NO;
            if (_dishSubView) {
                _dishSubView.hidden = YES;
            }
            if (_priceSubView) {
                _priceSubView.hidden = YES;
            }
            if (_othersSubView) {
                _othersSubView.hidden = YES;
            }
            if (_allSubView) {
                _allSubView.hidden = YES;
            }
            
            [_environmentSubView reloadData];
            [self.subView bringSubviewToFront:_environmentSubView];
            break;
        }
        case MerchantPictureTypeAll:{
            
            [_dishButton setBackgroundColor:[UIColor clearColor]];
            [_priceButton setBackgroundColor:[UIColor clearColor]];
            [_othersButton setBackgroundColor:[UIColor clearColor]];
            [_environmentButton setBackgroundColor:[UIColor clearColor]];
            [_allButton setBackgroundColor:[UIColor colorWithHex:0xffbdbbbb]];
            
            [self createAllSubView];
            _allSubView.hidden = NO;
            if (_dishSubView) {
                _dishSubView.hidden = YES;
            }
            if (_priceSubView) {
                _priceSubView.hidden = YES;
            }
            if (_othersSubView) {
                _othersSubView.hidden = YES;
            }
            if (_environmentSubView) {
                _environmentSubView.hidden = YES;
            }
            
            [_allSubView reloadData];
            [self.subView bringSubviewToFront:_allSubView];
            break;
        }
            
        default:
            break;
    }
    
}

#pragma -DiscountSubViewDelegate

- (void)beginRequestData
{
    if (!_progressHub)
    {
        _progressHub = [[MBProgressHUDEx alloc] initWithView:self.view TopHeight:self.subView.frame.origin.y withBottomHeight:0 withLeftWidth:0 withRightWidth:0 withExclusiveObjects:nil];
        [self.view addSubview:_progressHub];
    }
    [_progressHub setFrameWithView:self.view
                         TopHeight:self.subView.frame.origin.y
                  withBottomHeight:0
                     withLeftWidth:0
                    withRightWidth:0];
    [self.view bringSubviewToFront:_progressHub];
    _progressHub.delegate = self;
    _progressHub.labelText= @"加载中...";
    [_progressHub show:YES];
}

- (void)endRequestData
{
    [_progressHub hide:NO afterDelay:1.0];
}

-(void)requestFinishedData:(IDataModel *)discountDataModel{
    if ([discountDataModel isKindOfClass:[RCMerchantPicturesDataModel class]]) {
        self.dataModel = (RCMerchantPicturesDataModel *)discountDataModel;
        [self refreshHeaderButtonWithCategoryID];
    }
}

-(void)gotoChildSubViewWithData:(NSArray *)itemsArray withCurrentTag:(NSInteger)tag withHasChild:(BOOL)hasChild withImageView:(UIImageView *)imageView{
    KFLog(@"go to child");
    if (hasChild) {
        RCMerchantPictureItem *item = [itemsArray safeObjectAtIndex:tag];
        if (nil == item) {
            return;
        }
        RCMerchantAlbumDetailViewController *vc = [[RCMerchantAlbumDetailViewController alloc]initWithMerchantID:self.shopID andType:item.typeID];
        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }else{
        BTCityAndSceneScrollViewController *vc = [[BTCityAndSceneScrollViewController alloc]initWithRequestParam:itemsArray CurrentPageNumber:tag IsContainPictureInfo:YES LoadFromWeb:YES];
        vc.shouldShowAnimation = YES;
        
        UIImage *headerImage = imageView.image;
        
        
        CGRect rect = [self.view.superview convertRect:imageView.bounds fromView:imageView];
        rect.origin.y +=64;
        [vc setFromImage:headerImage fromWindowRect:rect];
        vc.animationDelegate = self;
        
        [RCAppDelegate.tabBarController setModalPresentationStyle:UIModalPresentationCurrentContext];
        [RCAppDelegate.tabBarController presentViewControllerWithCompatibility:vc animated:NO];
        [vc release];
    }
}

-(void)rightButtonClicked{
    
    if (![[GloableEngineService sharedInstance]alertLoginViewIfUnlogin:self]) {
        return;
    }
    
    RCMerchantUploadPhotoViewController *vc = [[RCMerchantUploadPhotoViewController alloc]initWithShopID:self.shopID];
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
}

-(void)manageButtonClicked{
    RCFansListVC *t = [[RCFansListVC alloc] init];
    t.vcType = FansListVCType_photoCheck;
    t.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:t animated:YES];
    [t release];
    
}

#pragma photoDelegate

-(BOOL)shouldAnimatedWhenViewDidDisappearForPhotoPreviewViewController:(BTCityAndSceneScrollViewController *)vc {
    return YES;
}

-(BOOL)shouldAnimatedWhenViewDidAppearForPhotoPreviewViewController:(BTCityAndSceneScrollViewController *)vc {
    return YES;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
